%save('calibA.mat','calibA','calibc')
load('calibA.mat');%读取校准数据，吸光度和浓度
[p,s]=polyfit(calibc,calibA,1);%一阶拟合
y1=polyval(p,calibc);
figure(1);
scatter(calibc,calibA,'k.');
hold on;
plot(calibc,y1,'b');
R2=1-s.normr^2/norm(calibA-mean(calibA))^2;

L0=64379;%换成实际测量值
L1=60186;%换成实际测量值
T=L1/L0;
A=-log10(T);
c=(A-p(2))/p(1);
ppm=c*14/1000
scatter(c,A,20,'r');
text(c+0.08,A,[num2str(c),'    R2=',num2str(R2)],'color','r','FontSize',10);

xlabel('umol/L');ylabel('A');title('亚硝酸盐氮吸光度校准曲线 540nm');
legend('校准数据','校准曲线','测量值');

mdl = fitlm(calibA,calibc);
R2=mdl.Rsquared.Ordinary
figure(2);
scatter(calibA,calibc,'k.');
hold on;
y1=table2array(mdl.Coefficients(2,1))*calibA+table2array(mdl.Coefficients(1,1));
plot(calibA,y1,'b');

c=table2array(mdl.Coefficients(2,1))*A+table2array(mdl.Coefficients(1,1));
ppm=c*14/1000
scatter(A,c,20,'r');
text(A+0.001,c,[num2str(c),'    R2=',num2str(R2)],'color','r','FontSize',10);
ylabel('umol/L');xlabel('A');title('亚硝酸盐氮吸光度校准曲线 540nm');
legend('校准数据','校准曲线','测量值');